//
//  LDYUserAccount.swift
//  李东阳微博
//
//  Created by 李东阳 on 16/4/19.
//  Copyright © 2016年 李东阳. All rights reserved.
//

import UIKit
//Optional({
//    "access_token" = "2.00nDZ86GajUO6Dbe1ba36ac3N5KRDE";
//    "expires_in" = 157679999;
//    "remind_in" = 157679999;
//    uid = 5872775023;
//})
class LDYUserAccount: NSObject,NSCoding {

        //MARK: -  用户授权的唯一票据
    var access_token : String?
    
        //MARK: - access_token的生命周期,单位是秒数
    var expires_in:Int = 0{
    
        didSet{
        expires_date =  NSDate().dateByAddingTimeInterval(Double(expires_in))
            
        }
    
    }
    
        //MARK: -  授权用户的UID
    var uid:String?
    
        //MARK: -  用户头像 高清大图
    var avatar_large:String?
    
    //Mark --用户头像
    var profile_image_url:String?

        //MARK: -  用户名称
    var screen_name : String?
    
    
    var expires_date:NSDate?
    
    
  init(dict: [String: AnyObject]){
    
    super.init()
    
    setValuesForKeysWithDictionary(dict)
    
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
            //MARK: -  我生命都不做

    }
    
//    screen_name
//    avatar_large
    override var description: String{
    
        let keys = ["access_token", "expires_date", "uid", "screen_name", "avatar_large", "profile_image_url" ]
        
        
    return  dictionaryWithValuesForKeys(keys).description
    }
    
        //MARK: -  归档

    func encodeWithCoder(aCoder: NSCoder) {
        
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(expires_date, forKey: "expires_date")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        aCoder.encodeObject(profile_image_url, forKey: "profile_image_url")
    }
    
    required init?(coder aDecoder: NSCoder) {
        
        access_token = aDecoder.decodeObjectForKey("access_token")as?String
        expires_date = aDecoder.decodeObjectForKey("expires_date")as?NSDate
        uid = aDecoder.decodeObjectForKey("uid")as?String
        screen_name = aDecoder.decodeObjectForKey("screen_name")as?String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large")as?String
        profile_image_url = aDecoder.decodeObjectForKey("profile_image_url")as?String
    }
    
    
    
    
}
